const express = require('express')
const app = express()
const config = require('./config/index')
const bodyParser = require('body-parser')
const chalk = require('chalk')
const cookieParase = require('cookie-parser')
const port = config.port
const passport = require('passport')
const logger = require('./utils/logger')
const router = require('./routers/index')
const expressSession = require('express-session')
app.use(expressSession(config.session))
app.use(cookieParase())
app.use(logger.netLog())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(passport.initialize())

require('./utils/passport')(passport);
app.use(router)
app.listen(port, err => {
  if (!err) {
    console.log(chalk.blue(`server run success: http://localhost:${port}`))
  } else {
    console.log(chalk.red(err))
  }
})